package com.kuzan.autocloud.common.model.system;

import com.kuzan.autocloud.common.model.Base;
import com.kuzan.autocloud.common.util.GsonUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import java.util.Map;

/**
 * <p>Description: 存储系统中删除的记录</p>
 *
 * @author kuzank
 */
@Data
@NoArgsConstructor
@Entity
@Table(name = "sys_deletion_record")
public class DeletionRecord extends Base {

    /**
     * 所属表
     */
    @Column(length = 32)
    private String form;
    private String collection;
    /**
     * 删除的表单记录信息 - json 结构
     */
    @Lob
    @Column(columnDefinition = "TEXT")
    private String content;


    public static DeletionRecord ofCollection(String collection, String creator, Map<String, Object> map) {

        DeletionRecord obj = new DeletionRecord();
        obj.setId(String.valueOf(map.get("id")));
        obj.setCreator(creator);
        obj.setContent(GsonUtil.gson.toJson(map));
        obj.setCollection(collection);
        return obj;
    }
}
